# encoding:utf-8
import requests,base64,json
'''
easydl图像分类
'''
def query_zy(img):
    #定义:我们训练模型所创建的接口url
    request_url = 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/classification/zhongyaoid'
    #定义:我们自己应用获取票据
    access_token='24.96e27ae0d98830746131fcb80da75a27.2592000.1605942967.282335-20231143'
    #定义headers 告诉服务器上传数据是json格式

    #将图片文件内容转换为base64
    # 把二进制数据转换为ascii码形式

    headers = {
        'Content-Type': 'application/json'
    }
    #定义上传给服务器的数据
    data = {
        "image": img,
        "top_num": 7
    }
    # 转换为json字符串
    body = json.dumps(data).encode('utf-8')

    # 拼接url
    request_url = request_url + "?access_token=" + access_token

    # 发起post请求把body参数发送给服务器端程序
    response = requests.post(request_url, body, headers=headers)

    result = None
    if response.status_code == 200:
        result = response.json()
    # print(result)
    return result



